home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / AmigaTalk / general / ArrayedCollection.st < prev    next >
Encoding:
Text File  |  2000-02-16  |  1.7 KB  |  72 lines

  1. Class ArrayedCollection :SequenceableCollection
  2. ! current !
  3. [
  4.     = anArray         ! i !
  5.         (self size ~= anArray size) 
  6.             ifTrue: [^ false]. i <- 0.
  7.                        self do: [:x | (x ~= (anArray at: (i <- i + 1)))
  8.                                   ifTrue: [^ false]].
  9.         ^ true
  10. |
  11.     at: key ifAbsent: exceptionBlock
  12.       ((key <= 0) or: [key > self size])
  13.          ifTrue: [^ exceptionBlock value].
  14.  
  15.       ^ self at: key
  16. |
  17.     coerce: aCollection      ! temp !
  18.       temp <- self class new: aCollection size.
  19.       temp replaceFrom: 1 to: aCollection size with: aCollection.
  20.       ^ temp
  21. |
  22.     copyFrom: start to: stop       ! size temp !
  23.       size <- stop - start + 1.
  24.       temp <- self class new: size.
  25.       temp replaceFrom: 1 to: size with: self startingAt: start.
  26.       ^ temp
  27. |
  28.     currentKey
  29.       ^ current
  30.     deepCopy ! newobj !
  31.       newobj <- self class new: self size.
  32.       (1 to: self size) do:
  33.          [:i | newobj at: i
  34.             put: (self at: i) copy ].
  35.  
  36.       ^ newobj
  37. |
  38.     do: aBlock
  39.       (1 to: self size) 
  40.           do: [:i | current <- i. 
  41.             aBlock value: (self at: i)]
  42. |
  43.     first
  44.       current <- 1.
  45.       ^ (current <= self size) 
  46.          ifTrue: [ self at: current]
  47. |
  48.     firstKey
  49.       ^ 1
  50. |
  51.     lastKey
  52.       ^ self size
  53. |
  54.     next
  55.       current <- current + 1.
  56.       ^ (current <= self size) 
  57.          ifTrue: [ self at: current]
  58. |
  59.     padTo: length
  60.       ^ (self size < length)
  61.           ifTrue: [ self , (self class new: (length - self size) ) ]
  62.          ifFalse: [ self ]
  63. |
  64.     shallowCopy ! newobj !
  65.       newobj <- self class new: self size.
  66.       (1 to: self size) do:
  67.          [:i | newobj at: i 
  68.                      put: (self at: i) ].
  69.       ^ newobj
  70. ]
  71.